package com.ysyx.ysyx_census.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @description: xxxx接口/类
 * @author:郭宇轩
 * @create:2023/4/21 15:46
 */
public class MonthUtils {

    public static List<String> getSixMonth() {

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        String tempDate = formatter.format(date);
        //返回值
        List<String> list = new ArrayList<String>();
        int month = Integer.parseInt(tempDate.substring(5, 7));
        int year = Integer.parseInt(tempDate.substring(0, 4));
        for (int i = 5; i >= 0; i--) {
            if (month > 6) {
                if (month - i >= 10) {
                    list.add(year + "-" + String.valueOf(month - i)+"-01");
                } else {
                    list.add(year + "-0" + String.valueOf(month - i)+"-01");
                }
            } else {
                if (month - i <= 0) {
                    if (month - i + 12 >= 10) {
                        list.add(String.valueOf(year - 1) + "-" + String.valueOf(month - i + 12)+"-01");
                    } else {
                        list.add(String.valueOf(year - 1) + "-0" + String.valueOf(month - i + 12)+"-01");
                    }
                } else {
                    if (month - i >= 10) {
                        list.add(String.valueOf(year) + "-" + String.valueOf(month - i)+"-01");
                    } else {
                        list.add(String.valueOf(year) + "-0" + String.valueOf(month - i)+"-01");
                    }
                }
            }
        }
        return list;

    }

}
